package ForTest;

public class Draw {
    private int height;

    public Draw(int height){
        if (height < 3){
            height = 3;
        }
        this.height = height;
    }

    /*
     绘制一个三角形。
    */
    public void draw_triangle(){
        System.out.println("=------------绘制三角形------------=");
        for (int y = 0; y < height; ++y) {
            System.out.print("    ");
            for (int x = 0; x < height - y; ++x) {
                System.out.print("*");
            }
            System.out.print("\n");
        }

        System.out.println("=----------------------------------=\n");
    }
    /*
     绘制一个矩形。
     \param width: 宽
    */
    public void draw_rect(int width){
        System.out.println("=-------------绘制矩形-------------=");
        if (width < 1) {
            width = 1;
            System.out.println("宽度过小，已规范为1.");
        }
        for (int y = 0; y < height; ++y) {
            System.out.print("    ");
            for (int x = 0; x < width; ++x) {
                System.out.print("*");
            }
            System.out.print("\n");
        }
        System.out.println("=----------------------------------=\n");
    }
    /*
     绘制一个正方形。
    */
    public void draw_square(){
        System.out.println("=------------绘制正方形------------=");
        for (int y = 0; y < height; ++y) {
            System.out.print("    ");
            for (int x = 0; x < height; ++x) {
                System.out.print("*");
            }
            System.out.print("\n");
        }
        System.out.println("=----------------------------------=\n");
    }
    /*
     绘制一个平行四边形。
     \param width: 底边边长
    */
    public void draw_parallelogram(int width){
        System.out.println("=----------绘制平行四边形----------=");
        if (width < 3) {
            width = 3;
            System.out.println("宽度过小，已规范为3.");
        }
        for (int y = 0; y < height; ++y) {
            System.out.print("    ");
            for (int x = 0; x < y; ++x) {
                System.out.print(" ");
            }
            for (int x = 0; x < width; ++x) {
                System.out.print("*");
            }
            System.out.print("\n");
        }
        System.out.println("=----------------------------------=\n");
    }
}
